import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { PloughResultItem } from "./PloughResultItem";
import { ScrollPolicy } from "../../../../../flashx/textLayout/container/ScrollPolicy";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Cache } from "../../../cache/Cache";
import { ECopyType } from "../../../../../Message/Public/ECopyType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
//class PloughCopyResultView
    
    export  class PloughCopyResultView extends View
    {
        constructor()
        {
            super();
            layer = LayerManager.alertLayer;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._button = ObjCreate.createGButton(Language.getString(36681), 172, 190, 70, 25, this, "ButtonSpecial");
            this._button.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClickHandler);
            addChild(this._button);
            this._tileList = ObjCreate.createTileList(120, 110, 170, 80, this);
            this._tileList.columnWidth = 40;
            this._tileList.rowHeight = 40;
            this._tileList.columnCount = 4;
            this._tileList.rowCount = 2;
            this._tileList.setStyle("cellRenderer", PloughResultItem);
            this._tileList.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._tileList.verticalScrollPolicy = ScrollPolicy.OFF;
            addChild(this._tileList);
            return;
        }

        public updateResult(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._img = new GImageBitmap(ImagesConst.PloughSuccessBg, 1, 1);
                addChild(this._img);
            }
            else 
            {
                this._img = new GImageBitmap(ImagesConst.PloughFailBg, 1, 1);
                addChild(this._img);
                this._imgTxt = new GImageBitmap(ImagesConst.PloughFailTxt, 97, 100);
                addChild(this._imgTxt);
            }
            if (this._button) 
            {
                addChild(this._button);
            }
            return;
        }

        public updateRewardList(arg1: Array<any>): void
        {
            if (this._tileList) 
            {
                addChild(this._tileList);
                this._tileList.dataProvider = new DataProvider(arg1);
                this._tileList.drawNow();
            }
            return;
        }

        /* internal  */onButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            if (this._img) 
            {
                this._img.dispose(true);
            }
            if (this._imgTxt) 
            {
                this._imgTxt.dispose(true);
            }
            if (this._tileList && this._tileList.parent == this) 
            {
                this.removeChild(this._tileList);
            }
            if (Cache.instance.copy.isInCopyType(ECopyType._ECopyPlough)) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PloughCopyLeft));
            }
            return;
        }

        /* internal */ /* var */_img: GImageBitmap;

        /* internal */ /* var */_imgTxt: GImageBitmap;

        /* internal */ /* var */_button: GButton;

        /* internal */ /* var */_tileList: GTileList;
    }
